/**
 * Created by WXH on 15-9-16.
 */

$(document).ready(function(){
    $("#suggest_ul").hide(0);
    $(".searchInp").keyup(function(){
        if($(".searchInp").val().length<=0){
            $("#lid_fid").val("");
            $(".suggest_ul").hide(0);
            return;
        }
        $.ajax({
            "url" : "http://www.12301.cc/call/jh_prod.php",
            "data" : {action:'admin_land_search', ltitle:$(".searchInp").val()},
            "dataType":"json",
            "type": 'POST',
            "success":function(data){
                $("#suggest_ul").show(0);
                var contents="";
                var list = data.list;
                for(var i in list){
                    var keywords =list[i]["title"];
                    var id = list[i]["id"];
                    contents=contents+"<li data-id='"+id+"'>"+keywords+"</li>";
                }
                $("#suggest_ul").html(contents);

            }
        });
    });
    $("#suggest_ul").on("click","li",function(e){
        var target = $(e.currentTarget);
        var id = target.data("id");
        $(".searchInp").val(target.text());
        $("#lid_fid").val(id);
        $("#suggest_ul").hide(0);
    })
    $(".inpBox").on('click','#button',function(e){
        var target    = $.trim($(".setColor_a").val());
        var name      = $.trim($("#name").val());
        var begintiem = $.trim($("#startDate").val())
        var endtime   = $.trim($("#endDate").val())
        var j=1
        var tnum=0;
        var torder=0;
        var money=0;
        $.ajax({
            url : "http://www.12301.cc/module/wxh/terminal/call/sql_double.php",
            type : "GET",
            dataType : "json",
            data : {
                name      : name,
                begintiem : begintiem,
                endtime   : endtime,
                target    : target
            },
            beforeSend:function(){
                $("#setimg").css("display","inline-block");
            },
            success:function(res){
                if(res.status=="fail")
                {
                    alert(res.msg)
                }else {
                    $("#countTotal").show()
                    var tbody      = $("#tbody");
                    var countTotal = $("#countTotal");
                    var html       = '';
                    for(var i in res){
                        var d       = res[i];
                        var p_type  = d["p_type"];
                        var title   = d["title"];
                        var jtype   = d["jtype"];
                        var tnums   = d["tnums"];
                        var moneys  = d["moneys"]/100;
                        var torders = d["torders"];
                        var dname   = d["dname"];
                        tnum        = tnums+tnum;
                        money       = money+moneys;
                        torder      = torder+torders
                        if(j%2==0)
                        {
                            html+='<tr style="background:#F7F7F7"><td class="setAlign setTd">'+p_type+'</td>';}
                        else{
                            html+='<tr style="background:#FFFFFF"><td class="setAlign setTd">'+p_type+'</td>';}
                        html+='<td class="setAlign setTd">'+jtype+'</td>'
                        html+='<td class="setAlign setTd">'+title+'</td>'
                        html+='<td class="setAlign setTd">'+dname+'</td>'
                        html+='<td class="setAlign setTd">'+torders+'</td>'
                        html+='<td >'+tnums+'</td>'
                        html+='<td class="setColor_a">￥'+moneys+'</td></tr>'
                        tbody.html(html);
                        j++
                    }
                    var htmlappend='';
                    htmlappend+='<ul><li>合计：<span class="setColor_a" id="total"></span>'
                    htmlappend+='<li>订单数：<span class="setColor_a" id="torder">'+torder+'</span></li>' ;
                    htmlappend+='<li>门票数：<span class="setColor_a" id="tnum">'+tnum+'</span></li>'
                    htmlappend+='<li>总金额：<span class="setColor_a" id="money">'+money.toFixed(2)+'</span></li> </ul></div>'
                    countTotal.html(htmlappend);
                }
            },
            complete:function(){
                $("#setimg").fadeOut("slow");
            }
        })
    } )
    $(".bottomBox").on('click','.floatL',function(e){
        var target   = $(e.currentTarget).val();
        var name     = $.trim($("#name").val());
        var begintiem= $.trim($("#startDate").val())
        var endtime  = $.trim($("#endDate").val())
        var j=1
        var tnum=0;
        var torder=0;
        var money=0;
        $.ajax({
            url : "http://www.12301.cc/module/wxh/terminal/call/sql_double.php",
            type : "GET",
            dataType : "json",
            data : {
                name      : name,
                begintiem : begintiem,
                endtime   : endtime,
                target    : target
            },
            beforeSend:function(){
                $("#setimg").css("display","inline-block");
            },
            success:function(res){
                if(res.status=="fail")
                {
                    alert(res.msg)
                }else {
                    $("#countTotal").show()
                    var tbody = $("#tbody");
                    var countTotal = $("#countTotal");
                    var html       = '';
                    for(var i in res){
                        var d       = res[i];
                        var p_type  = d["p_type"];
                        var title   = d["title"];
                        var jtype   = d["jtype"];
                        var tnums   = d["tnums"];
                        var moneys  = d["moneys"]/100;
                        var torders = d["torders"];
                        var dname   = d["dname"];
                        tnum        = tnums+tnum;
                        money       = money+moneys;
                        torder      = torder+torders
                        if(j%2==0)
                        {
                            html+='<tr style="background:#F7F7F7"><td class="setAlign setTd">'+p_type+'</td>';}
                        else{
                            html+='<tr style="background:#FFFFFF"><td class="setAlign setTd">'+p_type+'</td>';}
                        html+='<td class="setAlign setTd">'+jtype+'</td>'
                        html+='<td class="setAlign setTd">'+title+'</td>'
                        html+='<td class="setAlign setTd">'+dname+'</td>'
                        html+='<td class="setAlign setTd">'+torders+'</td>'
                        html+='<td >'+tnums+'</td>'
                        html+='<td class="setColor_a">￥'+moneys+'</td></tr>'
                        tbody.html(html);
                        j++
                    }
                    var htmlappend='';
                    htmlappend+='<ul><li>合计：<span class="setColor_a" id="total"></span>'
                    htmlappend+='<li>订单数：<span class="setColor_a" id="torder">'+torder+'</span></li>' ;
                    htmlappend+='<li>门票数：<span class="setColor_a" id="tnum">'+tnum+'</span></li>'
                    htmlappend+='<li>总金额：<span class="setColor_a" id="money">'+money+'</span></li> </ul></div>'
                    countTotal.html(htmlappend);
                }
            },
            complete:function(){
                $("#setimg").fadeOut("slow");
            }
        })


    } )


})

